package com.example.snowinfo;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;

public class ActivityAdapter extends BaseExpandableListAdapter implements
		ExpandableListAdapter {
	public Context context;

	private LayoutInflater vi;

	private String[][] data;

	int _objInt;

	private static final int GROUP_ITEM_RESOURCE = R.layout.group_item;

	private static final int CHILD_ITEM_RESOURCE = R.layout.child_item;

	public String[] check_string_array;

	public ActivityAdapter(Context context, Activity activity, String[][] data) {

		this.data = data;

		this.context = context;

		vi = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		_objInt = data.length;

		check_string_array = new String[_objInt];

	}

	public String getChild(int groupPosition, int childPosition) {

		return data[groupPosition][childPosition];

	}

	public long getChildId(int groupPosition, int childPosition) {

		return childPosition;

	}

	public int getChildrenCount(int groupPosition) {

		return data[groupPosition].length;

	}

	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {

		View v = convertView;

		String child = getChild(groupPosition, childPosition);

		int id_res = 0;

		if (groupPosition == 0) {

			/*
			 * if(childPosition == 0) id_res = R.drawable.audi_a4;
			 * 
			 * if(childPosition == 1) id_res = R.drawable.audi_q7;
			 * 
			 * if(childPosition == 2) id_res = R.drawable.audi_r8;
			 */

		}

		else if (groupPosition == 1) {

			/*
			 * if(childPosition == 0) id_res = R.drawable.bmw_m6;
			 * 
			 * if(childPosition == 1) id_res = R.drawable.bmw_x6;
			 */

		}

		else if (groupPosition == 2) {

			/*
			 * if(childPosition == 0) id_res = R.drawable.ferrari_enzo;
			 * 
			 * if(childPosition == 1) id_res = R.drawable.ferrari_f430;
			 * 
			 * if(childPosition == 2) id_res = R.drawable.ferrari_f430_italia;
			 */

		}

		else if (groupPosition == 3) {

			/*
			 * if(childPosition == 0) id_res = R.drawable.ferrari_enzo;
			 * 
			 * if(childPosition == 1) id_res = R.drawable.ferrari_f430;
			 * 
			 * if(childPosition == 2) id_res = R.drawable.ferrari_f430_italia;
			 */

		}
		else if (groupPosition == 4) {

			/*
			 * if(childPosition == 0) id_res = R.drawable.ferrari_enzo;
			 * 
			 * if(childPosition == 1) id_res = R.drawable.ferrari_f430;
			 * 
			 * if(childPosition == 2) id_res = R.drawable.ferrari_f430_italia;
			 */

		}
		else if (groupPosition == 5) {

			/*
			 * if(childPosition == 0) id_res = R.drawable.ferrari_enzo;
			 * 
			 * if(childPosition == 1) id_res = R.drawable.ferrari_f430;
			 * 
			 * if(childPosition == 2) id_res = R.drawable.ferrari_f430_italia;
			 */

		}
		if (child != null) {

			v = vi.inflate(CHILD_ITEM_RESOURCE, null);

			ViewHolder holder = new ViewHolder(v);

			holder.text.setText(Html.fromHtml(child));

			//holder.imageview.setImageResource(id_res);

		}

		return v;

	}

	public String getGroup(int groupPosition) {

		return "group-" + groupPosition;

	}

	public int getGroupCount() {

		return data.length;

	}

	public long getGroupId(int groupPosition) {

		return groupPosition;

	}

	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {

		View v = convertView;

		String group = null;

		int id_res = 0;

		long group_id = getGroupId(groupPosition);

		if (group_id == 0) {

			group = "Krvavec";

			// id_res = R.drawable.audi;

		}

		else if (group_id == 1) {

			group = "Mariborsko Pohorje";

			// id_res = R.drawable.bmw;

		}

		else if (group_id == 2) {

			group = "Rogla";

			// id_res = R.drawable.ferrari;

		}
		else if (group_id == 3) {

			group = "Krajnska Gora";

			// id_res = R.drawable.ferrari;

		}
		else if (group_id == 4) {

			group = "Cerkno";

			// id_res = R.drawable.ferrari;

		}
		else if (group_id == 5) {

			group = "Vogel";

			// id_res = R.drawable.ferrari;

		}

		if (group != null) {

			v = vi.inflate(GROUP_ITEM_RESOURCE, null);

			ViewHolder holder = new ViewHolder(v);

			holder.text.setText(Html.fromHtml(group));

			//holder.imageview.setImageResource(id_res);

		}

		return v;

	}

	public boolean isChildSelectable(int groupPosition, int childPosition) {

		return true;

	}

	public boolean hasStableIds() {

		return true;

	}

}
